<?php
class User_IndexController extends Zend_Controller_Action {
	public function init() {
		Zend_Loader::loadClass("UserModel");
	}
	public function preDispatch() {
		$this->view->module = $this->_request->getModuleName();
		$this->view->controller = $this->_request->getControllerName();
		$this->view->action = $this->_request->getActionName();
		
		//set layout
    	$layoutPath = APPLICATION_PATH  . '/templates/user/user';
		$option = array (	'layout' 		=> 'index', 
              	        'layoutPath' 	=> $layoutPath );
		Zend_Layout::startMvc ( $option );
	}
	
	function indexAction() {
		$userModel = new UserModel();
		
		
		$request =$this->_request;
		if ($request->isPost()) {
			if ($request->getParam("submit") == 'Save') {
				$user_name = $request->getParam("user_name");
				$full_name = $request->getParam("full_name");
				$email = $request->getParam("email");
				$phone = $request->getParam("phone");
				$password = hash("SHA256", $request->getParam("password"));
				
				
				$data = array(  "user_name"=>$user_name,
								"full_name"=>$full_name,
								"email"=>$email,
								"password"=>$password,
								"phone"=>$phone
							 );
				$userModel->insert($data);
			}
		}
		$this->view->list_user = $userModel->fetchAll("status = 1");
	}
	
	function loadRegionAjaxAction() {
		$layout = $this->_helper->layout();
		$layout->disableLayout();
		$request = $this->_request;
		if ($request->isPost()) {
			if ($request->getParam("do") == 'add') {
				$this->render('add');
			}else if($request->getParam("do") == 'edit'){
				$this->render('edit');
			}
		}else exit();
	}
	
}